import { Loading } from 'element-ui';

let loadingCount = 0;
let loading;

const startLoading = () => {
	loading = Loading.service({
		target: ".el-main",
		lock: true, //锁定屏幕滚动
		text: '正在处理，请稍等......',
		background: 'rgba(0, 0, 0, 0.6)'
	});
};

const endLoading = () => {
	loading.close();
};

export const showLoading = () => {
	if (loadingCount === 0) {
		startLoading();
	}
	loadingCount += 1;
};

export const hideLoading = () => {
	if (loadingCount <= 0) {
		return;
	}
	loadingCount -= 1;
	if (loadingCount === 0) {
		endLoading();
	}
};
